//
//  ObjcController.m
//  microblog
//
//  Created by cy on 2017/8/28.
//  Copyright © 2017年 Aisino. All rights reserved.
//

#import "ObjcController.h"
#import "UIColor+CZAddition.h"
#import "UIViewController+OAExtension.h"
#import "ATLTabBarController.h"

#import <microblog-Swift.h>


@interface ObjcController ()
    
@end


@implementation ObjcController

    
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" fontSize:16 target:self action:@selector(back) isBack:YES];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一个" fontSize:16 target:self action:@selector(next) isBack:NO];
    
    
    self.view.backgroundColor = [UIColor cz_randomColor];
    
    
    UIImage *img = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
    img = [img imageWithTintColor:[UIColor orangeColor]];
    UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
    imgView.frame = self.view.bounds;
    [self.view addSubview:imgView];
}
    
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
//        [self.stackControllers addObject:self.navigationController.viewControllers.lastObject];
//        [self.navigationController setViewControllers:self.stackControllers animated:false];
    });
}
    
- (void)back {
    NSInteger count = self.navigationController.childViewControllers.count;
    if (count == 1) {  // 返回到 Swift 页面
        MainController *tabBarVC = [MainController new];
        AppDelegate *ojbcRoot = (AppDelegate *)[UIApplication sharedApplication].delegate;
        ojbcRoot.window.rootViewController = tabBarVC;
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
    
- (void)next {
    ObjcController *next = [ObjcController new];
    [self.navigationController pushViewController:next animated:YES];
}
    
    
@end
